# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=starship
pkgver=1.9.1
pkgrel=0
pkgdesc="Minimal, blazing-fast and infinitely customizable prompt for any shell"
url="https://starship.rs"
arch="x86_64 armv7 armhf aarch64 x86 ppc64le"  # limited by rust/cargo
license="ISC"
makedepends="
	cargo
	dbus-dev
	libgit2-dev
	openssl1.1-compat-dev
	zlib-dev
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	$pkgname-zsh-plugin:_zsh_plugin:noarch
	"
source="https://github.com/starship/starship/archive/v$pkgver/$pkgname-$pkgver.tar.gz
	use-libdbus.patch
	minimize-size.patch
	starship.plugin.zsh
	"

# http feature is used just for reporting bugs
_cargo_opts="--frozen --no-default-features --features notify"

prepare() {
	default_prepare

	# No --locked, we have to update Cargo.lock.
	cargo fetch
}

build() {
	cargo build $_cargo_opts --release

	local i; for i in bash fish zsh; do
		./target/release/starship completions $i > target/starship.$i
	done
}

check() {
	# Some tests sporadically fail, try to repeat 3 times before failing.
	local i; for i in $(seq 0 3); do
		[ $i -eq 0 ] || msg "Retrying ($i/3)..."
		cargo test $_cargo_opts && return 0
		sleep 1
	done
	return 1
}

package() {
	install -D -m755 target/release/starship -t "$pkgdir"/usr/bin/
	install -D -m644 target/starship.bash "$pkgdir"/usr/share/bash-completion/completions/starship
	install -D -m644 target/starship.fish "$pkgdir"/usr/share/fish/completions/starship.fish
	install -D -m644 target/starship.zsh "$pkgdir"/usr/share/zsh/site-functions/_starship
}

_zsh_plugin() {
	pkgdesc="$pkgdesc (Zsh plugin)"
	depends="$pkgname=$pkgver-r$pkgrel"

	install -D -m644 "$srcdir"/starship.plugin.zsh \
		-t "$subpkgdir"/usr/share/zsh/plugins/starship/
}

sha512sums="
b5f0ddbe08ff563368c30c6f2b9b9451b7f424d009362a2cb1cf2d4552b51a0937a914e9e39f1e734594aea092afea15322039ad951a3ad3cc05eac7afad769a  starship-1.9.1.tar.gz
b79ad6935e8fd0e8094843009e92ffd4e52754142eb76907dcfc28a747518a5a98066469018f413f3f58074704f68bbe63a793340cbb83cd1da1d3c92e176131  use-libdbus.patch
cc30cf72c8657b08efdbd299300dc5fc529a2c0899ef96a75e432ee50100c1c8c8f9692587409091bfa218d964dd4f4f07d950fa0d947649f9f8e72042b8712b  minimize-size.patch
384a3b84b103005d347ef76c9a61f8c5e21cc97f17f195cff157f71f42dbd76fd6f54f93715cbebbee2eab70a275e39917334721fa21d130bd715a7b6334418b  starship.plugin.zsh
"
